#!/usr/bin/env node

const yargs = require("yargs");

function withSubCommand() {
  const argv = require("yargs")
    .scriptName("say")
    .usage("$0 <cmd> [args]")
    .command(
      "hello [name]",
      "welcome somebody to yargs!",
      (yargs) => {
        yargs.positional("name", {
          type: "string",
          default: "Cambi",
          describe: "the name to say hello to",
        });
      },
      function (argv) {
        console.log("hello", argv.name, "welcome to yargs!");
      }
    )
    .help().argv;

  console.log("🚀 ~ withSubCommand ~ argv:", argv);
}

function withoutSubCommand() {
  const argv = require("yargs")
    .scriptName("say")
    .usage("$0 <words>")
    .positional("words", {
      type: "string",
      describe: "what you want to say",
    })
    .help().argv;
  console.log("🚀 ~ withoutSubCommand ~ argv:", argv);
}

function myTest() {
  const parser = yargs(process.argv.slice(2))
    .options({
      a: { type: "boolean", default: false },
    })
    .help("help")
    .alias("help", "h");

  const argv = parser.parse();

  console.log("🚀 ~ sometest ~ argv:", argv);
}

function exampleTest() {
  const argv = require("yargs")(process.argv.slice(2))
    .usage("This is my awesome program\n\nUsage: $0 [options]")
    .help("help")
    .alias("help", "h")
    .version("version", "1.0.1")
    .alias("version", "V")
    .options({
      input: {
        alias: "i",
        description: "<filename> Input file name",
        requiresArg: true,
        required: true,
      },
      output: {
        alias: "o",
        description: "<filename> output file name",
        requiresArg: true,
        required: true,
      },
    })
    .parse();

  console.log("Inspecting options");
  console.dir(argv);

  console.log("input:", argv.input);
  console.log("output:", argv.output);
}

function exampleTestB() {
  var yargs = require("yargs/yargs")(process.argv.slice(2));

  var argv = yargs
    .usage("This is my awesome program")
    .options({
      input: {
        description: "Input file name",
        requiresArg: true,
        alias: "i",
      },
      output: {
        description: "Output file name",
        requiresArg: true,
        alias: "o",
      },
    })
    .parse();

  yargs.showHelp();

  console.log("\n\nInspecting options");
  console.dir(argv);
}

function exampleTestC() {
  var argv = require("yargs/yargs")(process.argv.slice(2)).demand(2).parse();
  console.dir(argv);
}

function main() {
  // myTest();
  // exampleTest();
  // exampleTestB();
  exampleTestC();
  // withSubCommand();
  // withoutSubCommand();
}

main();
